package cn.lizemin.i18n.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Locale;

/**
 * @author lzm
 * @date 2025/9/28 18:55
 * @description
 */
@RestController
public class HelloController {

    private static final Logger log = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    MessageSource messageSource;

    @GetMapping("/hello")
    public String hello(@RequestParam("name") String name, @RequestParam("key") String key) {
        Locale locale = LocaleContextHolder.getLocale();
        log.info("当前语言环境为：{}", locale);
        return messageSource.getMessage(key, new Object[]{name}, locale);
    }


}
